package Text_90;

import java.util.Scanner;

public class Code {

	public static void main(String[] args) {
		 int[] arr = {2,4,8,10,14,18,19,30};
	        Scanner s = new Scanner(System.in);
	        System.out.println("请输入查询的数：");
	        int num = s.nextInt();
	        int i = select(arr, num);
	        if(i<0) {
	            System.out.println("数组中没有找到想要查找的数");
	        }else {
	            //查找的数的索引
	            System.out.println("查找的数的索引"+i);
	        }
	    }
//	    public static int select(int[] arr,int trage){
//	       int i = 0;
//	       int j = arr.length-1;
//	       while(i<=j){
//	           int m = (i+j)>>1;
//	           if(arr[m]<trage){
//	               i = m + 1;
//	           }
//	           else if(trage<arr[m]){
//	                j = m - 1;
//	           }
//	           else {
//	               return m;
//	           }
//	       }
//	        return -1;
//	    }

	    public static int select(int[] arr,int trage){
	        int i = 0;
	        int j = arr.length;
	        while(i<j){
	            int m = (i+j)>>1;
	            if(arr[m]<trage){
	                i = m ;
	            }
	            else if(trage<arr[m]){
	                j = m - 1;
	            }
	            else {
	                return m;
	            }
	        }
	        return -1;

	}

}
